package com.huawei.fastengine.fastview.download.utils;

import android.content.Context;
import android.content.pm.PackageManager.NameNotFoundException;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.provider.Settings.Secure;
import com.huawei.fastengine.fastview.download.utils.log.FastViewLogUtils;
import com.huawei.hwid.core.constants.HwAccountConstants;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public final class SettingUtil {
    private static final int AGREE_USER_EXPERIENCE_VALUE = 1;
    private static final String COLUMN_USER_EXPERIENCE_INVOLVED = "user_experience_involved";
    private static final String TAG = "SettingUtil";
    private static boolean hasCheckSupportUserExperience = false;
    private static boolean isSupportUserExperience = true;

    public static boolean hasUserExperienceConfig(Context context) {
        if (!hasCheckSupportUserExperience) {
            try {
                context.getPackageManager().getApplicationInfo("com.huawei.bd", 8192);
            } catch (NameNotFoundException e) {
                FastViewLogUtils.i(TAG, " isSupportUserExperience: bd is not installed");
                try {
                    context.getPackageManager().getApplicationInfo("com.huawei.lcagent", 8192);
                } catch (NameNotFoundException e2) {
                    isSupportUserExperience = false;
                    FastViewLogUtils.i(TAG, "isSupportUserExperience: lcagent is not installed");
                }
            }
            hasCheckSupportUserExperience = true;
            FastViewLogUtils.d(TAG, "isSupportUserExperience: has checked， need not check again, isSupportUserExperience = " + isSupportUserExperience);
        }
        return isSupportUserExperience;
    }

    public static boolean isAgreeUserExperience(Context context) {
        int i = Secure.getInt(context.getContentResolver(), COLUMN_USER_EXPERIENCE_INVOLVED, -1);
        FastViewLogUtils.d(TAG, "get settings userExperienceInvolved value, userExperienceInvolved=" + i);
        return i == 1;
    }

    public static boolean isChinaRom() {
        String str;
        String str2 = "";
        String str3 = "";
        try {
            Class cls = Class.forName("android.os.SystemProperties");
            Method declaredMethod = cls.getDeclaredMethod("get", new Class[]{String.class});
            Object invoke = declaredMethod.invoke(cls, new Object[]{"ro.product.locale.language"});
            Object invoke2 = declaredMethod.invoke(cls, new Object[]{"ro.product.locale.region"});
            if (invoke != null) {
                str2 = (String) invoke;
            }
            str3 = invoke2 != null ? (String) invoke2 : str3;
            str = str2;
        } catch (ClassNotFoundException e) {
            str = str2;
            FastViewLogUtils.e(TAG, " getProductConfig ClassNotFoundException.");
        } catch (NoSuchMethodException e2) {
            str = str2;
            FastViewLogUtils.e(TAG, " getProductConfig NoSuchMethodException.");
        } catch (IllegalArgumentException e3) {
            str = str2;
            FastViewLogUtils.e(TAG, "getProductConfig IllegalArgumentException.");
        } catch (IllegalAccessException e4) {
            str = str2;
            FastViewLogUtils.e(TAG, "getProductConfig IllegalAccessException.");
        } catch (InvocationTargetException e5) {
            str = str2;
            FastViewLogUtils.e(TAG, "getProductConfig InvocationTargetException.");
        }
        return "zh".equalsIgnoreCase(str) && HwAccountConstants.DEFAULT_SIMPLE_COUNTRY_CODE.equalsIgnoreCase(str3);
    }

    public static boolean isNetworkAvailable(Context context) {
        if (context == null) {
            return false;
        }
        boolean isAvailable;
        ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService("connectivity");
        if (connectivityManager != null) {
            NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
            if (activeNetworkInfo != null) {
                isAvailable = activeNetworkInfo.isAvailable();
                FastViewLogUtils.i("", "Network IsAvailable: " + isAvailable);
                return isAvailable;
            }
            FastViewLogUtils.i("", "Network NotAvailable");
        }
        isAvailable = false;
        FastViewLogUtils.i("", "Network IsAvailable: " + isAvailable);
        return isAvailable;
    }
}
